const {query} = require('../utils/mysql.js')
module.exports={
    // 获取数据并且分页的sql语句
    async _getsecurityServer(page,size){
        const start = (page-1) * size;
        const sql = `select * from stu_security limit ?,?`;
        return await query(sql,[start,size])
    },
    // 根据id删除单条数据的sql语句
    async _deletesecurityServer(id){
        const sql = `delete from stu_security where id = ?`
        return await query(sql,[id])
    },
    // 根据id对单条数据进行修改的sql语句
    async _updatesecurityServer({id,name,img,location,access,num}){
        const sql = `update stu_security set name=?,img=?,location=?,access=?,num=? where id = ?`
        return await query(sql,[name,img,location,access,num,id])
    },
    //添加数据到数据库的sql语句
    async _addsecurityServer({name,img,location,access,num}){
        const sql = `insert into stu_security (name,img,location,access,num) values (?,?,?,?,?)`
        return await query(sql,[name,img,location,access,num])
    },
    // 批量删除数据的sql语句
    async _BatchdeletionSecurityServer(ids){
        const sql = `delete from stu_security where id in (${ids})`
        return await query(sql)
    },
    // 多条件查询
    async _selectsecurityServer({name,address}){
        let sql = ` select * from  cms_student  where 1 = 1 `
        let arr = []
        if(name != ''){
            arr.push(`name = '${name}'`)
        }
        if(address != ''){
            arr.push(`address = '${address}'`)
        }
        if (arr.length > 0) {  
            sql += ` and ${arr.join(' and ')}`;      
        }  
        return await query(sql)
    }
}